package com.kd.controller.admin;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.kd.bean.admin.Admin_msg;
import com.kd.service.admin.IAdmin_msgService;

/**
 * 管理员   管理员详细信息
 * 控制层
 * @author ZFC
 *
 */
@Controller
@RequestMapping("/admin_msg")
public class Admin_msgController {
	
	
	@Autowired
	private IAdmin_msgService admin_msgService;
	
	@RequestMapping("/main")
	public String toMain() {
		return "/view/main.jsp";
	}
	
	@RequestMapping("/adminLogin")
	public String adminLogin(Admin_msg admin,Model m,HttpSession session) {
		String msg = null;
		try {
			Admin_msg adminMsg = admin_msgService.adminLogin(admin);
			msg = adminMsg==null?"登录失败,请检查后在尝试登录！":"登录成功";
			if(adminMsg!=null) {
				session.setAttribute("adminMsg", adminMsg);
				m.addAttribute("msg", msg);
				return "/view/admin/adminMain.jsp";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		m.addAttribute("msg", msg);
		return "/view/admin/adminLogin.jsp";
	}
	
	@RequestMapping("/adminEsc")
	public String adminEsc(HttpSession session) {
		session.invalidate();
		return "redirect:/view/admin/adminLogin.jsp";
	}
}
